package org.dormi.learn;

import java.util.function.Function;

/**
 * @author : dormi330
 * @since : 21/11/15
 */
public class FunctionComposition {
    public static void main(String[] args) {

        Function<Integer, Integer> multiply = (value) -> value * 2;
        Function<Integer, Integer> add = (value) -> value + 3;

        // Function 具有 andThen方法
        Function<Integer, Integer> v2 =  add.andThen(multiply);
        Integer result2 = v2.apply(3);
        System.out.println(result2);    // 12


        Function<Integer, Integer> addThenMultiply = multiply.compose(add);
        Integer result1 = addThenMultiply.apply(3);
        System.out.println(result1);    // 12

    }
}
